/**
 * 牛股席位追踪管理初始化
 */
var NiubilityBrank = {
    id: "NiubilityBrankTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
NiubilityBrank.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
            {title: '代码', field: 'gScode', visible: true, align: 'center', valign: 'middle',width : 100},
            {title: '名称', field: 'gSname', visible: true, align: 'left', valign: 'middle',width : 300},
            {title: '机构席位', field: 'gSalesName', visible: true, align: 'center', valign: 'middle'},
            {title: '总买卖(万)', field: 'gPbuy', visible: true, align: 'center', valign: 'middle'},
            {title: '操作日期', field: 'gTdate', visible: true, align: 'center', valign: 'middle'},
            {title: '席位明细', field: 'gSalesDetail', visible: true, align: 'left', valign: 'middle',width : 380},
    ];
};

/**
 * 检查是否选中
 */
NiubilityBrank.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if(selected.length == 0){
        Feng.info("请先选中表格中的某一记录！");
        return false;
    }else{
        NiubilityBrank.seItem = selected[0];
        return true;
    }
};

/**
 * 点击添加牛股席位追踪
 */
NiubilityBrank.openAddNiubilityBrank = function () {
    var index = layer.open({
        type: 2,
        title: '添加牛股席位追踪',
        area: ['800px', '420px'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/niubilityBrank/niubilityBrank_add'
    });
    this.layerIndex = index;
};

/**
 * 打开查看牛股席位追踪详情
 */
NiubilityBrank.openNiubilityBrankDetail = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '牛股席位追踪详情',
            area: ['800px', '420px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/niubilityBrank/niubilityBrank_update/' + NiubilityBrank.seItem.id
        });
        this.layerIndex = index;
    }
};

/**
 * 删除牛股席位追踪
 */
NiubilityBrank.delete = function () {
    if (this.check()) {
        var ajax = new $ax(Feng.ctxPath + "/niubilityBrank/delete", function (data) {
            Feng.success("删除成功!");
            NiubilityBrank.table.refresh();
        }, function (data) {
            Feng.error("删除失败!" + data.responseJSON.message + "!");
        });
        ajax.set("niubilityBrankId",this.seItem.id);
        ajax.start();
    }
};

/**
 * 查询牛股席位追踪列表
 */
NiubilityBrank.search = function () {
    var queryData = {};
    queryData['dm'] = $("#dm").val();
    queryData['date'] = $("#date").val();
    queryData['name'] = $("#name").val();
    NiubilityBrank.table.refresh({query: queryData});
};

$(function () {
    var defaultColunms = NiubilityBrank.initColumn();
    var table = new BSTable(NiubilityBrank.id, "/niubilityBrank/list", defaultColunms);
    table.setPaginationType("server");
    NiubilityBrank.table = table.init();
});
